﻿using System;
using System.Collections.Generic;

using VIT.Business;
using VIT.Library.Web;
using VIT.Web.UI;
using System.Data;

namespace VIT.Web
{
    public partial class Partners : VIT.Web.UI.VITComponent
    {
        public string vId;
        protected void Page_Load(object sender, EventArgs e)
        {
            vId = Request["sId"];
        }

        protected new void Page_PreInit(object sender, EventArgs e)
        {
            base.Page_PreInit(sender, e);

            BLCategory c = new BLCategory();
            c.LanguageId = Session["language"].ToString();
            DataTable table = c.GetListChuildCat(30);
            foreach (DataRow row in table.Rows)
            {
                LoadSkinEmptyTop(row["id"].ToString(), row["Title"].ToString());
            }
        }

        private bool LoadModule(Web.Controls.Skin skin, string moduleName, Dictionary<string, string> pars, string title = "")
        {
            var module = LoadControl(URL.appPath + "Modules/" + moduleName + "/" + moduleName + ".ascx") as VITModule;
            var controlSkin = LoadControl(URL.appPath + "Skins/" + skin.SkinName + ".ascx") as VITSkin;
            controlSkin.Title = title;
            module.Params = pars;
            skin.Controls.Add(controlSkin);
            var container = controlSkin.FindControl("PlaceHolderContent");
            container.Controls.Add(module);
            return true;
        }

        private void LoadSkinEmptyTop(string cat, string title)
        {
            var pars = new Dictionary<string, string>();
            //if (CatID == "25")
            //{
            //    pars["Position"] = "BannerThiepCuoi";
            //}
            //else
            //{
            //    pars["Position"] = "Banner";
            //}
            //pars["Top"] = "4";
            pars["Category"] = cat;
            LoadModule(SkinCenter, "PartnersByCat", pars, title);
        }
    }
}
